<?php

	class Util
	{

		function cauta($content,$strStart,$strStop)
		{
			$response     = array();
			$new_content2 = $content;
			while(strpos($new_content2,$strStart) !== false)
			{
				$pos1         = strpos($new_content2,$strStart);
				$new_content2 = substr($new_content2,$pos1+strlen($strStart));
				$pos2         = strpos($new_content2,$strStop);
				$slice        = substr($new_content2,0,$pos2);
				$new_content2 = substr($new_content2,$pos2+strlen($strStop));
				array_push($response,$slice);
			}
			return $response;
		} 	

		function EndsWith( $str, $sub ) 
		{
			return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub );
		}

		function StartsWith( $str, $sub ) 
		{
			return ( substr( $str, 0, strlen( $sub )  ) === $sub );
		}

		function LastPage()
		{
			$lp = Util::GetCurrentUrl();
			$lp = str_replace("?","~",$lp);
			$lp = str_replace("&","#",$lp);
			return $lp;
		}

		function ReturnLastPage( $lp )
		{
			$lp = str_replace("~","?",$lp);
			$lp = str_replace("#","&",$lp);
			return $lp;
		}

		function Redirect($url)
		{
			echo 
			'
				<script language="javascript">
					window.location="'.$url.'";
				</script>
			';
		}

		function GetCurrentUrl( $base_url )
		{
			$ret  = $base_url."?";
			$arr  = $_GET;
			$vals = array_keys($arr);
			foreach($vals as $val)
			{
				$ret.= $val."=".$arr[$val]."&";
			}
			$ret = substr($ret,0, strlen($ret)-1);
			return $ret;
		}

		function GetCurrentUrlWithoutKeys($keys)
		{
			$ret = $_SERVER['PHP_SELF']."?";
			$arr = $_GET;
			$vals= array_keys($arr);
			foreach($vals as $val)
			{
				if( array_search($val, $keys) === false ) 
				$ret .= $val."=".$arr[$val]."&";
			}
			$ret = substr($ret,0, strlen($ret)-1);
			return $ret;
		}

		function GetCurrentUrlReplacingVal($base_url, $key, $value)
		{
			$ret = $base_url."?";
			$arr = $_GET;
			$vals= array_keys($arr);
			foreach($vals as $val)
			{
				if( $val != $key )
				{
					$ret .= $val."=".$arr[$val]."&";
				}
				else
				{
					$ret .= $val."=".$value."&";
				}
			}
			$ret = substr($ret,0, strlen($ret)-1);
			return $ret;
		}

}
//aici voi pune niste functii globale

function ParsMysql($sql)
{
	$keywordColor = '#0000ff';
	$wordColor    = '#ff9900';
	$tab          = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	$ret = strtolower( $sql );
	$ret = str_replace("select", "<br><font color='".$keywordColor."'>SELECT</font><br>".$tab, $ret);
	$ret = str_replace("where", "<br><font color='".$keywordColor."'>WHERE</font><br>".$tab, $ret);
	$ret = str_replace("asc", "<font color='".$keywordColor."'>ASC</font>", $ret);
	$ret = str_replace("as", "<font color='".$keywordColor."'>AS</font>", $ret);
	$ret = str_replace("and", "<font color='".$keywordColor."'>AND</font>", $ret);
	$ret = str_replace("order by", "<br><font color='".$keywordColor."'>ORDER BY</font>", $ret);
	$ret = str_replace("group by", "<br><font color='".$keywordColor."'>GROUP BY</font>", $ret);
	$ret = str_replace("limit", "<font color='".$keywordColor."'>LIMIT</font>", $ret);
	$ret = str_replace("update", "<br><font color='".$keywordColor."'>UPDATE</font><br>".$tab, $ret);
	$ret = str_replace("delete", "<br><font color='".$keywordColor."'>DELETE</font><br>".$tab, $ret);
	$ret = str_replace("from", "<br><font color='".$keywordColor."'>FROM</font><br>".$tab, $ret);
	$ret = str_replace("set", "<font color='".$keywordColor."'>WHERE</font>", $ret);
	$ret = "<font color='".$wordColor."'>".$ret."</font>";
	return $ret;
}

function CleanPostAndGet()
{
	foreach($_POST as $key => $val)
	{
		$_POST[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
		$$key        = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
	}
	foreach($_GET as $key => $val)
	{
		$_GET[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
		$$key       = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
	}
}

?>

